//
//  LGFollowDataSyptomCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//

#import "LGFollowDataWeightCell.h"

#define baseWidth       (Screen_W-viewPix(56))
#define dateWidth       (92/320.0)*baseWidth
#define weightWidth     (118/320.0)*baseWidth

@interface LGFollowDataWeightCell()
/**   */
@property (nonatomic , strong)UIView *shadowView;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIView *topLineView;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *weightLabel;
/**   */
@property (nonatomic , strong)UIButton *statusBtn;
/**   */
@property (nonatomic , strong)UILabel *bmiLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;

@end

@implementation LGFollowDataWeightCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setShowCorner:(BOOL)showCorner{
    _showCorner = showCorner;
    CGFloat bottom = (showCorner == YES)?-viewPix(10):0;
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.shadowView).offset(bottom);
    }];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = dataDic[@"record_time"];
    //体重
    NSString *weightStr = LGNSString(dataDic[@"weight"]);
    self.weightLabel.text = weightStr;
    NSString *different = LGNSString(dataDic[@"diffstatus"]);
    NSDictionary *iconDic = @{@"up":@"监测-偏高",@"down":@"监测-偏低"};
    if(different.length>0){
        self.statusBtn.hidden = NO;
        NSString *color = [different isEqualToString:@"up"]?@"#DB453A":@"#3291FF";
        [self.statusBtn setTitleColor:[UIColor colorWithString:color] forState:UIControlStateNormal];
        [self.statusBtn setImage:[UIImage imageNamed:iconDic[different]] forState:UIControlStateNormal];
        [self.statusBtn setTitle:LGNSString(dataDic[@"diffvalue"]) forState:UIControlStateNormal];
    }else{
        self.statusBtn.hidden = YES;
    }
    CGFloat width = [weightStr textWidthWithFont:LGFont(14) maxHeight:MAXFLOAT]+3;
    [self.statusBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weightLabel.mas_centerX).offset(width/2.0);
    }];
    
    //BMI
    self.bmiLabel.text = LGNSString(dataDic[@"bmi"]);
    NSString *status = LGNSString(dataDic[@"bmi_status"]);
    NSDictionary *titleDic = @{@"0":@"正常",@"1":@"偏胖",@"2":@"肥胖",@"3":@"偏瘦"};
    NSDictionary *colorDic = @{@"0":@"#429BFF",@"1":@"#FF9704",@"2":@"#E53C39",@"3":@"#3DC997"};
    self.statusLabel.text = titleDic[status];
    self.statusLabel.textColor = [UIColor colorWithString:colorDic[status]];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.shadowView];
    [self.shadowView addSubview:self.baseView];
    [self.shadowView addSubview:self.topLineView];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.weightLabel];
    [self.baseView addSubview:self.statusBtn];
    [self.baseView addSubview:self.bmiLabel];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.lineView1];
    [self.baseView addSubview:self.lineView2];
    [self.shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-viewPix(5));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(viewPix(5));
    }];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shadowView).offset(viewPix(12));
        make.right.equalTo(self.shadowView).offset(-viewPix(12));
        make.top.equalTo(self.shadowView);
        make.bottom.equalTo(self.shadowView).offset(0);
        make.height.equalTo(@(viewPix(40)));
    }];
    [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.baseView);
        make.top.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.left.equalTo(self.baseView);
        make.width.equalTo(@(dateWidth));
    }];
    [self.weightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(weightWidth));
    }];
    [self.statusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weightLabel.mas_centerX).offset(15);
        make.centerY.equalTo(self.weightLabel);
        make.width.equalTo(@(viewPix(40)));
        make.height.equalTo(@(viewPix(30)));
    }];
    [self.bmiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.left.equalTo(self.weightLabel.mas_right);
        make.right.equalTo(self.baseView).offset(-viewPix(10));
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bmiLabel.mas_centerX).offset(15);
        make.centerY.equalTo(self.bmiLabel);
    }];
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.dateLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.baseView);
        make.left.equalTo(self.weightLabel.mas_right);
        make.width.equalTo(@(0.5));
    }];

}
-(UIView *)shadowView{
    if(!_shadowView){
        _shadowView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.layer.borderColor = [UIColor colorWithString:@"#E0E0E0"].CGColor;
        _baseView.layer.borderWidth = 1;
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

-(UIView *)topLineView{
    if(!_topLineView){
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _topLineView;
}

-(UIView *)lineView1{
    if(!_lineView1){
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView1;
}


-(UIView *)lineView2{
    if(!_lineView2){
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView2;
}


-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"日期" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _dateLabel;
}

-(UILabel *)weightLabel{
    if(!_weightLabel){
        _weightLabel = [UILabel lableWithText:@"体重" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _weightLabel;
}

-(UIButton *)statusBtn{
    if(!_statusBtn){
        _statusBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(14) textColor:@"#DB453A" imageName:@""];
        _statusBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _statusBtn;
}

-(UILabel *)bmiLabel{
    if(!_bmiLabel){
        _bmiLabel = [UILabel lableWithText:@"BMI" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _bmiLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _statusLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
